
#include "BSP.h"
#include <jansson.h>


//jansson Test
void jansson_pack_test(void)
{
//    json_t *root;
//    char *out;

//    root = json_pack("{s:s,s:s,s:s,s:s,s:s,s:s,s:s}",
//							device_init.appid,device_init.appid_num,
//							device_init.batch,device_init.batch_num,
//							device_init.date,device_init.date_num,
//							device_init.hard,device_init.date_num,
//							device_init.project,device_init.project_num,
//							device_init.soft,device_init.soft_num,
//							device_init.type,device_init.type_num
//							);

//    out = json_dumps(root, JSON_ENCODE_ANY);
//    printf("out:%s\r\n", out);
//    free(root);
//    free(out);
//	
//char * paramsBuf = "{\"appid\":\"10023325\",\"led\":1000.22}";
char * paramsBuf ="{\"return_code\":\"SUCCESS\",\"weixinurl\":\"http://cy.colorfulfield.com/weixinurl\",\"appid\":\"356566075136994\"}";	

json_error_t err;  

json_t* root = json_object();
json_t* led = json_object();
json_t* appid = json_object();

root = json_loads(paramsBuf, strlen(paramsBuf), &err);  

if(NULL != root && json_is_object(root))  
{  			
      json_t* return_code = json_object_get(root, "return_code");  
      if(NULL != return_code && json_is_string(return_code))  
      {  
				printf("return_code:%s\r\n",json_string_value(return_code) );
      }		
      json_t* weixinurl = json_object_get(root, "weixinurl");  
      if(NULL != weixinurl && json_is_string(weixinurl))  
      {  
				printf("weixinurl:%s\r\n",json_string_value(weixinurl) );
      }	
      json_t* appid = json_object_get(root, "appid");  
      if(NULL != appid && json_is_string(appid))  
      {  
				printf("appid_value:%s\r\n",json_string_value(appid) );
      }				
}  
  
json_decref(root);  
}
